import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-30
 * Time: 11:13
 */
public class letter_CasePermutation {
    StringBuffer path;

    List<String> ret;

    public List<String> letterCasePermutation(String s) {
        path = new StringBuffer();
        ret = new ArrayList<String>();
        dfs(s, 0);
        return ret;
    }

    void dfs(String s, int pos) {
        if (pos == s.length()) {
            ret.add(path.toString());
            return;
        }

        //不改变
        char c = s.charAt(pos);
        path.append(c);
        dfs(s, pos + 1);
        path.deleteCharAt(path.length() - 1);
        // 恢复现场

        //改变
        if (c < '0' || c > '9') {
            char ch = change(c);
            path.append(c);
            dfs(s, pos + 1);
            path.deleteCharAt(path.length() - 1);
        }
    }

    char change(char c) {
        if (c >= 'a' && c <= 'z') {
            return c -= 32;
        } else {
            return c += 32;
        }
    }
}
